package com.priox.sigar.application.mappers.handler;

import com.mm.seguridad.domain.model.Estado;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedTypes;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@MappedTypes(Estado.class)
public class EstadoTypeHandler implements TypeHandler<Estado> {

    public void setParameter(PreparedStatement preparedStatement, int i, Estado item, JdbcType jdbcType) throws SQLException {
        preparedStatement.setLong(i, item.getCode());
    }

    public Estado getResult(ResultSet resultSet, String s) throws SQLException {
        return Estado.findByCode(new Long(resultSet.getString(s)));
    }

    public Estado getResult(CallableStatement callableStatement, int i) throws SQLException {
        return Estado.findByCode(callableStatement.getLong(i));
    }
}
